//
//  main.swift
//  TestApp
//
//  Created by andyge on 15/8/3.
//  Copyright © 2015年 gejingguo. All rights reserved.
//

import Foundation
import SwiftTCP

print("hello")
testFunc()

var tcpClient = SwiftTCP.TcpClient()
var err = tcpClient.connect("127.0.0.1", port: 8900)
if err != nil {
    print("tcp connect failed, code:\(err!.errorCode), msg:\(err!.errorMsg)")
    exit(1)
}

//var str = "hello world."
//str.withCString() { cs in tcpClient.send(cs, size: 13) }

var data = [Int8](count:25, repeatedValue: 122)
//print(data)

//data.withUnsafeBufferPointer(<#T##body: (UnsafeBufferPointer<T>) -> R##(UnsafeBufferPointer<T>) -> R#>)
var dataPtr = UnsafeMutableBufferPointer<Int8>(start: &data, count: data.count)
//dataPtr.
//var dataPtr = UnsafeMutablePointer<Int8>(&data)

err = tcpClient.send(dataPtr.baseAddress, size: dataPtr.count)
if err != nil {
    print("send data failed, code:\(err!.errorCode), msg:\(err!.errorMsg)")
    exit(1)
}

err = tcpClient.send()
if err != nil {
    print("send data failed, code:\(err!.errorCode), msg:\(err!.errorMsg)")
    exit(1)
}

print("data send ..")

err = tcpClient.recv()
if err != nil {
    print("recv data failed, code:\(err!.errorCode), msg:\(err!.errorMsg)")
    exit(1)
}

exit(0)